package com.nbsaas.boot.project.rest.convert;

import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.project.api.domain.request.ProjectTaskCommentRequest;
import com.nbsaas.boot.project.data.entity.ProjectTask;
import com.nbsaas.boot.project.data.entity.ProjectTaskComment;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 任务评论请求对象转换成实体对象
 */

public class ProjectTaskCommentEntityConvert implements Converter<ProjectTaskComment, ProjectTaskCommentRequest> {

    @Override
    public ProjectTaskComment convert(ProjectTaskCommentRequest source) {
        ProjectTaskComment result = new ProjectTaskComment();
        BeanDataUtils.copyProperties(source, result);
        if (source.getTask() != null) {
            ProjectTask task = new ProjectTask();
            task.setId(source.getTask());
            result.setTask(task);
        }
        if (source.getUser() != null) {
            User user = new User();
            user.setId(source.getUser());
            result.setUser(user);
        }
        return result;
    }
}

